Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and static assert assumptions on size_t layout #576

Merged
merged 1 commit into from
Dec 13, 2020
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Dec 13, 2020

Rust specifies that usize is ABI compatible with C's uintptr_t: https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#isize-and-usize. However there is no direct Rust equivalent for size_t. C does not guarantee that size_t and uintptr_t are compatible. In practice though, on all platforms supported by Rust, they are identical for ABI purposes. See the libc crate which unconditionally defines libc::size_t = usize. We expect the same here and the assertions in this PR are just to explicitly document that.

Note that no assumption is made about C++ name mangling of signatures containing these types, not here nor anywhere in CXX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant